package com.onstar.cn.api;

import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.RequestMapping;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.sqlite.entities.RequestEventEntity;

/**
 * @Title: OperateB2CService.java
 * @Description:事件上传report
 * @author Xiaofeng Feng
 * @date 2015年8月13日 下午2:15:18
 */
@Path("/daap/EventService/api/data")
public class OperateB2CService {
	/*{"accountID":"account","appID":"864895026552842","channelID":"1",
		"data":[{"content":"{\"status\":\"success\",\"time\":\"1439538278044\",\"transactionID\":\"F0101\",\"version\":\"5.0.1\"}"
			,"eventID":"1"}],"deviceID":"864895026552842","deviceOS":"5.0.2","deviceToken":"864895026552842","deviceType":"MI 4",
		"eventTS":"1439538324034","language":"zh"}*/
	
	private String serverURL;
	
	public OperateB2CService(String serverURL) {
		this.serverURL = "https://proxy.shanghaionstar.com";
	}
	
	@RequestMapping("/upload")
	public RequestEntity eventReport(RequestEntity requestEntity, RequestEventEntity reportList) {
		if (requestEntity == null) {
			requestEntity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "eventReport", requestEntity, reportList);
		
		requestEntity.setUrl(serverURL + url);
		requestEntity.setBody(GsonHelper.toJson(reportList));
		return requestEntity;
	}
}
